package com.example.hotelmanagement.mapper;

import com.example.hotelmanagement.entity.Booking;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookingMapper {

    // 获取所有预订
    @Select("SELECT * FROM bookings")
    List<Booking> getAllBookings();

    // 根据 ID 获取单个预订
    @Select("SELECT * FROM bookings WHERE id = #{id}")
    Booking getBookingById(Long id);

    // 插入新预订
    @Insert("INSERT INTO bookings (user_id, hotel_id, check_in_date, check_out_date, status) " +
            "VALUES (#{userId}, #{hotelId}, #{checkInDate}, #{checkOutDate}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")  // 自动生成ID
    void insertBooking(Booking booking);

    // 更新已有预订
    @Update("UPDATE bookings SET user_id = #{userId}, hotel_id = #{hotelId}, " +
            "check_in_date = #{checkInDate}, check_out_date = #{checkOutDate}, status = #{status} " +
            "WHERE id = #{id}")
    void updateBooking(Booking booking);

    // 删除预订
    @Delete("DELETE FROM bookings WHERE id = #{id}")
    void deleteBooking(Long id);
}
